// JavaScript Document
var isasync=true;

function ajaxSettingsasync(a){
	isasync=a;
	$.ajaxSettings.async = a;
}
 
function dopost(urll,aa,b){
	 $.ajax({
			url : urll,
			data :  JSON.stringify(aa),
			async:isasync,
			contentType : "application/json;",
			dataType : "json",
			type : "POST",
			success :b,
			error: function(){
				toast('访问'+urll+'发生错误');
			}
		});

}


function doput(urll,aa,b){
	 $.ajax({
			url : urll,
			data :  JSON.stringify(aa),
			async:isasync,
			contentType : "application/json;",
			dataType : "json",
			type : "PUT",
			success :b,
			error: function(){
				toast('访问发生错误');
			}
		});

}



function getUrldata(aa){
	var params = new GetRequest();
	return decodeURI(params[aa]);
}
/**
 *获取url中的参数
 */
function GetRequest() {
	var vars = [], hash;
	var index_jinhao=window.location.href.indexOf('#');
	var str= window.location.href.slice(window.location.href.indexOf('?') + 1);
	if(index_jinhao!=-1){
		str= window.location.href.slice(window.location.href.indexOf('?') + 1,window.location.href.indexOf('#'));
	}
	var hashes =str.split('&');
	for (var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
};


 

function browserRedirect() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    var uri=document.location.href;
    if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
    	//pc端
    	
    	var index=uri.indexOf("/wap/");
    	if(index>-1){
    		document.location.href=getUrl("index.html");
    	}
        
    }else{
    	//手机端
    	var index=uri.indexOf("/wap/");
    	if(index>-1){
    	}else{
    		document.location.href=getUrl("/wap/index.html");
    	}
    }
}



function toast(msg){
	/**
	 var theme = "b",
	 msgText = msg,
	 textVisible =true,
     textonly = true;
     html ="";
    $.mobile.loading( "show", {
		text: msgText,
        textVisible: textVisible,
        theme: theme,
        textonly: textonly,
        html: html
   	 });
*/
$('body').append('<div style="width:100%;height:100%;position:fixed;top:0px;left:0px;background-color:rgba(0,0,0,0.3);text-align:center;z-index:10001" class="mydialog"><div style="max-width: 60%;min-width: 60%;font-size:14px;display:inline-block;background-color:rgba(255,255,255,1);margin-top:120px;text-align: left;padding: 1.3em 1.3em;"><div style="min-height:70px"> '+msg+'</div><div><a onClick="toastdispear()" style="float:right;color:#0C0">确认</a></div></div></div>');

	 $('.mydialog').focus();
	//setTimeout('toastdispear()',1500);
}


 


function toast_touming(msg){
	/**
	 var theme = "b",
	 msgText = msg,
	 textVisible =true,
     textonly = true;
     html ="";
    $.mobile.loading( "show", {
		text: msgText,
        textVisible: textVisible,
        theme: theme,
        textonly: textonly,
        html: html
   	 });
*/
$('body').append('<div style="width:100%;height:100%;position:fixed;top:0px;left:0px;background-color:rgba(0,0,0,0.5);text-align:center;z-index:10001" class="mydialog"><div style="margin-top:70%;padding:0.5em 1em"><div >'+msg+'</div></div></div>');
	 
	setTimeout('toastdispear()',1500);
}




function toastwithaction(msg,aa){
/*
	$.mobile.loading( "show", {
            text: msg,
            textVisible: true,
            theme: 'b',
            textonly: true,
            html: ''
    });
	*/
	
	$('body').append('<div style="width:100%;height:100%;position:fixed;top:0px;left:0px;background-color:rgba(0,0,0,0.3);text-align:center;z-index:10001" class="mydialog"><div style="max-width: 60%;min-width: 60%;display:inline-block;background-color:rgba(255,255,255,1);margin-top:120px;text-align: left;padding: 1.3em 1.3em;"><div style="min-height:70px"> '+msg+'</div><div><a id="toast_cmf" style="float:right;color:#0C0">确认</a></div></div></div>');
	$('#toast_cmf').click(function(){
		
		aa();
		toastdispear();
	});
}


/**
 * var bb=[];
 * 
 * var aa={}; aa.NAME="确认"; aa.ACTION=function(){ delAAddr(id); };
 * 
 * bb.push(aa); aa={}; aa.NAME="取消"; aa.ACTION=function(){
 *  }; bb.push(aa); toastwithactions("确认删除?",bb);
 */
function toastwithactions(msg,aa){
/*
 * $.mobile.loading( "show", { text: msg, textVisible: true, theme: 'b',
 * textonly: true, html: '' });
 */
	
	
	$('body').append('<div style="width:100%;height:100%;position:fixed;top:0px;left:0px;background-color:rgba(0,0,0,0.3);text-align:center;z-index:10001" class="mydialog"><div style="max-width: 60%;min-width: 60%;display:inline-block;background-color:rgba(255,255,255,1);margin-top:120px;text-align: left;padding: 1.3em 1.3em;"><div style="min-height:70px"><a onclick="toastdispear()" style="float:right;color:#999">x</a>'+msg+'</div><div id="toast_btns"></div></div></div>');
	var right_btn="";
	$.each(aa,function(index,item){
		 
		$('#toast_btns').append('<a id="toast_cmf_'+index+'" style="float:right;color:#0C0;margin-right:1.3em">'+item.NAME+'</a>');
		$('#toast_cmf_'+index).click(function(){
			item.ACTION();
			toastdispear();
		});
		
	});
}

function toastdispear(){
	//$.mobile.loading( "hide" );
	$('.mydialog').remove();
}

function Gobackandrefresh(){
	history.go(-1);location.reload();
	 
}



